package ipc;

import java.lang.reflect.InvocationTargetException;

public class Worker implements Runnable {

	public Class cl;
	public Class[] args;
	private Object[] initargs;
	public Object actualObject;
	
	public Worker(Class c, Object... args) throws ClassNotFoundException{
		cl = c;
		
		this.initargs = args;
		
		this.args = new Class[args.length];

		for( int i = 0 ; i < args.length; ++i ){
			this.args[i] = args[i].getClass();
		}
	}
	
	@SuppressWarnings("unchecked")
	public void run() {
//		System.out.println("running ");
		try {
			actualObject = cl.getConstructor(args).newInstance(initargs);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
